package com.nothing.composedemo

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.nothing.composedemo.ui.theme.ComposeDemoTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposeDemoTheme {
                // A surface container using the 'background' color from the theme
                Surface(color = MaterialTheme.colors.background) {
                    ShowRow()
                }
            }
        }
    }
}


@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    ComposeDemoTheme {
//        ShowRow()
        //  ShowColumn()
        HomeScreen()
    }
}


@Composable
private fun ShowColumn() {

    Column(
        Modifier
            .padding(16.dp),
    ) {
        Box(
            modifier = Modifier
                .background(Color.Blue, shape = RectangleShape)
                .width(20.dp)
                .height(20.dp)
        )
        Spacer(Modifier.height(4.dp))
        Box(
            modifier = Modifier
                .background(
                    Color.Green,
                    shape = RoundedCornerShape(16.dp)
                )
                .height(20.dp)
                .width(20.dp)
        )
        Spacer(modifier = Modifier.height(4.dp))
        Image(
            painter = painterResource(id = R.mipmap.a),
            contentDescription = "调皮",
            modifier = Modifier
                .height(160.dp)
                .fillMaxWidth()
                .clip(shape = RoundedCornerShape(8.dp)),
            contentScale = ContentScale.Crop
        )
        Spacer(
            modifier = Modifier
                .height(4.dp)
                .background(Color.Magenta)
        )
        Row {
            Box(
                modifier = Modifier
                    .height(16.dp)
                    .weight(1f)
                    .background(Color.Red)
            )
            Box(
                modifier = Modifier
                    .height(16.dp)
                    .weight(3f)
                    .background(Color.Cyan)
            )
        }
    }
}


@Composable
private fun ShowRow() {
    Row(
        modifier = Modifier
            .height(60.dp)
            .padding(16.dp)
    ) {
        Text("RandB")
        Spacer(modifier = Modifier.width(12.dp))
        Text(
            text = "Symbol",
            modifier = Modifier
                .width(40.dp)
                .height(32.dp),
            fontFamily = FontFamily.Monospace,
            fontSize = 16.sp,
            fontStyle = FontStyle.Italic
        )
        Spacer(
            modifier = Modifier
                .width(12.dp)
                .background(Color.Cyan)
        )
        Text(
            text = "Nature",
            modifier = Modifier.clickable {
                Log.e("--->", "Hello Nature !")
            },
            fontStyle = FontStyle.Normal,
            fontSize = 16.sp
        )
        Text(text = "测试_1", textDecoration = TextDecoration.Underline)
        Spacer(modifier = Modifier.width(12.dp))
        Text(text = "测试_1", textDecoration = TextDecoration.LineThrough)
        Spacer(modifier = Modifier.width(12.dp))
        Text(text = "测试_1", fontWeight = FontWeight.Bold)
        Spacer(modifier = Modifier.width(12.dp))
        Text(text = "Thin", fontWeight = FontWeight.Thin)
        Spacer(modifier = Modifier.width(12.dp))
        Text(text = "SemiBold", fontWeight = FontWeight.SemiBold)
        Spacer(modifier = Modifier.width(12.dp))
    }

}


@Composable
private fun HomeScreen() {
    Scaffold(topBar = {},
        drawerContent = {},
        content = {})
}